package com.lishao.soccer.service.impl;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.List;

import com.lishao.soccer.bean.entity.SmUser;
import com.lishao.soccer.bean.entity.TmScoreList;
import com.lishao.soccer.bean.form.TmScoreListForm;
import com.lishao.soccer.dao.TmScoreListMapper;
import com.lishao.soccer.service.TmScoreListService;

public class TmScoreListServiceImpl implements TmScoreListService {
	TmScoreListMapper tmScoreListMapper;

	public List<TmScoreList> selectByTeam(Long teamId){
		return tmScoreListMapper.selectByTeam(teamId);
	}
	public TmScoreList selectByPrimaryKey(Long tmScoreListId){
		return tmScoreListMapper.selectByPrimaryKey(tmScoreListId);
	}
	
	public boolean saveScoreList(TmScoreListForm tmScoreListForm,SmUser smUser){
		boolean bResult=false;
		int iResult = 0;
		TmScoreList tmScoreList = new TmScoreList();
		tmScoreList.setRowId(tmScoreListForm.getRowId());
		tmScoreList.setTeamId(tmScoreListForm.getTeamId());
		tmScoreList.setListName(tmScoreListForm.getListName());
		DateFormat df1 = new SimpleDateFormat("yyyy-MM-dd");
		try {
			tmScoreList.setStartDate(df1.parse(tmScoreListForm.getStartDate()));
			tmScoreList.setEndDate(df1.parse(tmScoreListForm.getEndDate()));
		} catch (Exception e) {
			e.printStackTrace();
		}
		tmScoreList.setGameDataFlag(tmScoreListForm.getGameDataFlag());
		tmScoreList.setDisciplineFlag(tmScoreListForm.getDisciplineFlag());
		tmScoreList.setRemark(tmScoreListForm.getRemark());
		tmScoreList.setDeletedFlag("0");
		tmScoreList.setCreatedBy(smUser.getRowId());
		tmScoreList.setCreatedDate(new java.util.Date());
		if(tmScoreList.getRowId()==null||tmScoreList.getRowId()==-1){
			iResult = tmScoreListMapper.insertSelective(tmScoreList);
		}else{
			iResult = tmScoreListMapper.updateByPrimaryKeySelective(tmScoreList);
		}
		bResult=iResult==1?true:false;
		return bResult;
	}
	//get set
	public TmScoreListMapper getTmScoreListMapper() {
		return tmScoreListMapper;
	}

	public void setTmScoreListMapper(TmScoreListMapper tmScoreListMapper) {
		this.tmScoreListMapper = tmScoreListMapper;
	}
	
}
